package com.alex.mvppractice.image;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alex.mvppractice.R;
import com.alex.mvppractice.utils.CommonAdapter;
import com.alex.mvppractice.utils.MyHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * ***********************************************************
 * author: alex
 * time: 16/7/19 上午11:31
 * name:
 * overview:
 * usage:
 * *************************************************************
 */
public class ImageFragment extends Fragment {

    @InjectView(R.id.recycle_view)
    RecyclerView mRecycleView;
    @InjectView(R.id.swipe_refresh_widget)
    SwipeRefreshLayout mSwipeRefreshWidget;

    private List<String> mDatas;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_image, container, false);
        ButterKnife.inject(this, view);

        initDatas();
        initRecyclerView();
        return view;
    }

    private void initDatas() {
        mDatas = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            mDatas.add("data::" + i);
        }
    }

    private void initRecyclerView() {
        mRecycleView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecycleView.setAdapter(new CommonAdapter<String>(getActivity(), mDatas, R.layout.item_layout_id) {
            @Override
            public void bindData(MyHolder holder, int position, String bean) {
                holder.setText(bean, R.id.tv_test)
                        .setTextColor(R.id.tv_test, getResources().getColor(R.color.primary));
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
